
function u_match_save_submit(){
	document.getElementById("match_introduce").value = $('#summernote').summernote('code');
	$("#form-u_match-add").Validform({
		tiptype:2,
		ajaxPost:true,
		callback:function(form){
			var index = parent.layer.getFrameIndex(window.name);
			if (index){//关闭弹出层
				parent.$('.btn-refresh').click(); 
				parent.layer.close(index);
			}else{//单独的页面
				location.href = web_path+"/backstage/u_match-info-list"; 
			}
		}
	});
}

function add_new_charge() {
	
	var rowLen = $('#charge').find('tbody tr').length + 1;
	var html = "<tr  class='text-c'>"
		+"<td><input type='text'"
		+"class='input-text' name='prize_num' datatype='n' nullmsg='不能为空并且必须是整数'></td>"	
		+"<td><input type='text'"
		+"class='input-text' name='prize_name' ></td>"	
		+"<td><input type='text'"
		+"class='input-text' style='min-width: 10px'"
		+"name='winner_count' datatype='n1-100' nullmsg='不能为空并且必须是整数'></td>"	
		+"<td>"
		+"<input type='text'  name='prize_percent' class='input-text' ></td>"
		+"<td>"
		+"<input type='text'  name='prize_money' class='input-text' ></td>"
		+"<td>"
		+"<input type='text'  name='remark' class='input-text' ></td>"	
		+"<td><button class='btn btn-warning radius' type='button'>"
		+"<i class='fa fa-remove'>&#xe632;</i> 删除</button></td>"		
		+"</tr>";
	$('#charge').find('tbody').append(html);
	$('#charge').find('tbody tr:last').find('button').on('click',
	function() {
		$(this).parent().parent().remove();
		/*$('#charge').find('tbody tr').each(function() {
			var rowIndex = $(this).index() + 1;
			$(this).find('td:eq(0)').text(rowIndex);
		})*/
	}); 
	
}

$(function() {
	/*外页上传*/
	var $list = $('#fileList_pre'),

	ratio = window.devicePixelRatio || 1,
	thumbnailWidth = 100 * ratio,
	thumbnailHeight = 100 * ratio,
	uploader,uploader_pre_prcture_inn;
	uploader = WebUploader.create({
		auto: true,
		swf: 'lib/webuploader/0.1.5/Uploader.swf',
		server: web_path+'/backstage/common/uploadPic',
		pick: '#filePicker_pre',
		
		formData : {
			foldername : 'resource'
		}
	});

	uploader.on( 'fileQueued', function( file ) {
		
		var $li = $(
			'<div id="' + file.id + '" class="file-item thumbnail">' +
			'<img>' +
			'<div class="info">' + file.name + '</div>' +
			'</div>'
			),
		$img = $li.find('img');

		$list.append( $li );
		uploader.makeThumb( file, function( error, src ) {
			if ( error ) {
				$img.replaceWith('<span>不能预览</span>');
				return;
			}

			$img.attr( 'src', src );			
			//$("#show_thumb").style.display = 'none';
			document.getElementById("show_thumb").style.display="none";
		}, thumbnailWidth, thumbnailHeight );
		
	});

	uploader.on( 'uploadSuccess', function(file, response) {
		$( '#'+file.id ).addClass('upload-state-done');
		$("#thumbnail").val(response.datas);				
	});

	uploader.on( 'uploadError', function( file ) {
		var $li = $( '#'+file.id ),
		$error = $li.find('div.error');
		if ( !$error.length ) {
			$error = $('<div class="error"></div>').appendTo( $li );
		}

		$error.text('上传失败');
	});

	uploader.on( 'uploadComplete', function( file ) {
		$( '#'+file.id ).find('.progress').remove();
	});
});
